{extend name="base" /}
{block name="css"}
{css href="__CSS__/authorize.css" /}
{/block}
{block name="body"}
<!-- 主要内容 开始 -->
<div class="weui-tab__bd-item">
  <header class="weui-navBar weui-navBar-fixed">
    <a href="javascript:history.go(-1);" class="weui-navBar-item">
      <i class="icon iconfont icon-fanhui"></i>
    </a>
    <div class="weui-center">
      <span class="weui-center-title">实名认证</span>
    </div>
    <a href="javascript:;" class="weui-navBar-item">
    </a>
  </header>
  <div class="weui-cells weui-cells_form">
    <div class="weui-cell">
      <div class="weui-cell__hd"><label class="weui-label">姓名</label></div>
      <div class="weui-cell__bd">
        {if $data.is_real}
          <p>{$data.real_name|substr_replace='*',3,3}</p>
        {else}
          <input class="weui-input" id="name" type="text" placeholder="请输入姓名">
        {/if}
      </div>
    </div>
    <div class="weui-cell">
      <div class="weui-cell__hd"><label class="weui-label">身份证</label></div>
      <div class="weui-cell__bd">
        {if $data.is_real}
          <p>{$data.idcard|substr_replace='********',6,8}</p>
        {else}
          <input class="weui-input" id="idcard" maxlength="18" type="text" placeholder="请输入身份证号" >
        {/if}
      </div>
    </div>
  </div>
  <div class="weui-btn-area">
    {if $data.is_real}
    <button class="weui-btn weui-btn_plain-primary">已认证</button>
    {else}
    <button class="weui-btn weui-btn_primary">确定</button>
    {/if}
  </div>
</div>
<!-- 主要内容 结束 -->
{/block}
{block name="js"}
<script type="text/javascript">
  $(function () {
    $('.weui-btn_primary').click(function () {
      var name = $('#name').val();
      var id = $('#idcard').val();
      if(!name) return $.toptip('姓名不能为空!');
      else if(!id || !/\d{18}/.test(id)) return $.toptip('请输入18位身份证号!');
      else $.confirm("认证后将不可修改，确定要认证吗?", "实名认证", function() {
        //保存用户数据
        $.post('authorize.html',{name:name,id:id,type:'id card'},function(res){
          if (res.code ===1 ){
            $.toast(res.msg,'text');
            setTimeout(function(){
              location.href = res.url;
            },600);
          }else{
            $.toptip(res.msg);
          }
        });
      }, function() {
        //取消操作
      });
    });
  });
</script>
{/block}